package com.qf;

import com.qf.model.Spit;
import com.qf.utils.IdWorker;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringRunner;


import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class test {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private IdWorker idWorker;

    @Test
    public void demo01(){
        List<Spit> spits = mongoTemplate.findAll(Spit.class);
        spits.stream().forEach(o-> System.out.println(o));
        System.out.println("================================");

        //条件构建对象
        org.springframework.data.mongodb.core.query.Criteria userid = org.springframework.data.mongodb.core.query.Criteria
                .where("userid").lt("2000").gt("1000");
        List<Spit> spits2 = mongoTemplate.find(new Query(userid), Spit.class);
        //spits2.stream().forEach(o-> System.out.println(o));
        System.out.println("================================");



//        Spit spit = new Spit();
//        spit.set_id("777");
//        spit.setNickname("lililili");
//        spit.setContent("qweasdzxcqweasd");
//        Spit save = mongoTemplate.save(spit);
//        System.out.println(save);


        Spit byId = mongoTemplate.findById(777, Spit.class);
        Criteria criteria = new Criteria("_id").in(777);
        Query query = new Query(criteria);
        Spit spit = new Spit();
        spit.setVisits(123123123);

//        mongoTemplate.updateMulti(query,spit,Spit.class);


    }
}
